<template>
  <div>
    <!--面包屑导航-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--contain-->
    <el-card>
      <!--search-->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable>
            <el-button slot="append" icon="el-icon-search" @click="searchInput"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!--table-->
      <el-table border stripe :data="ordersList">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" width="500px"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template v-slot:default="scope">
            <el-tag type="success" v-if="scope.row.order_pay==1">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="280px">
          <template v-slot:default="scope">{{scope.row.create_time|dateFormat}}</template>
        </el-table-column>
        <el-table-column label="下单操作">
          <el-button type="success" icon="el-icon-position" size="small" @click="showOrdersExpress"></el-button>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-sizes="[5, 10, 20, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageTotals"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      ></el-pagination>
    </el-card>
    <!--物流信息-->
    <el-dialog title="查看物流进度" :visible.sync="showDialogVisible" width="50%">
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(item,i) in this.expressInfo"
          :key="i"
          :timestamp="item.time"
        >{{item.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 订单列表请求参数
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      pageTotals: 0,
      // 订单列表表格
      ordersList: [],
      showDialogVisible: false,
      expressInfo: []
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    // 获取订单列表
    async getOrdersList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.ordersList = res.data.goods
      this.pageTotals = res.data.total
    },
    // 搜索
    searchInput() {
      console.log(this.queryInfo)
      this.getOrdersList()
    },
    // 监听当前页数
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getOrdersList()
    },
    // 监听每页显示条数
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getOrdersList()
    },
    // 查看物流信息
    async showOrdersExpress() {
      this.showDialogVisible = true
      const { data: res } = await this.$http.get('kuaidi/1106975712662')
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流状态失败！')
      }
      this.expressInfo = res.data
    }
  }
}
</script>

<style lang="less" scoped>
</style>
